import axios,{ResDataType} from "./axios"

type SearchType ={
  keyword:string,
  isStar:boolean,
  isDeleted:boolean,
  page:number,  // 当前页
  pageSize:number // 当前页数量
}
// 获取单个问卷信息
export async function getQuestionService(id:string):Promise<ResDataType>{
  const url = `/api/question/${id}`
  const data = (await axios.get(url)) as ResDataType
  return data
}
// 创建问卷
export async function createQuestion():Promise<ResDataType>{
  const url = '/api/question'
  const data = (await axios.post(url)) as ResDataType
  return data
}
// 获取列表
export async function getQuestionList(opt:Partial<SearchType>={}):Promise<ResDataType>{
  const url = '/api/question'
  const data = (await axios.get(url,{params:opt})) as ResDataType
  return data
}
// 更新单个问卷
export async function updateQuestion(id:string,opt:{[key:string]:any}):Promise<ResDataType>{
  const url = `/api/question/${id}`
  const data = (await axios.patch(url,opt)) as ResDataType
  return data
}
// 复制问卷
export async function copyQuestion(id:string):Promise<ResDataType>{
  const url = `/api/question/copy/${id}`
  const data = (await axios.post(url)) as ResDataType
  return data
}
// 批量删除
export async function deleteQuestion(ids:string[]):Promise<ResDataType>{
  const url = `/api/question`
  const data = (await axios.delete(url,{data:{ids}})) as ResDataType
  // TODO 这个data:{ids}不理解
  return data
}